#ifndef UIHELPER_H
#define UIHELPER_H

#include <vector>
#include <string>
#include <map>
#include "hgeheader.h"

namespace UIHelper
{
	static const int screen_backcolor = 0xff000000;
	typedef std::vector<std::string> StrVec;
	struct WidgetDef
	{
		WidgetDef()
		{
			backcolor = screen_backcolor;
			forcolor = 0xff000000;
			align = 1;
			x=0;y=0;w=0;h=0;column=1;edge=1;
		}
		int x;
		int y;
		int w;
		int h;
		int column;
		int edge;
		int backcolor;
		int forcolor;
		int align;
		StrVec items;
	};
	typedef std::map<std::string, WidgetDef *> WidgetDefMap;
	static WidgetDefMap widgetmap;
	void Load();
	WidgetDef *GetWidgetDef( std::string key );
	
	typedef std::vector<int> ListIntVec;
	struct List
	{
		enum{ common, entered, escaped, };
		enum{ left, center, };
		List()
		{
			selection = 0;
			column = 1;
			startrow = 0;
			backcolor = screen_backcolor;
			forcolor = 0xff000000;
			align = center;
			renderedge = true;
			selectionx = 0;
			selectiony = 0;
			hideselection = false;
		}
	private:
		StrVec contents;
		ListIntVec itemdatas;
	public:
		gcn::Rectangle area;
		int column;
		int selection;
		int startrow;
		int forcolor;
		int backcolor;
		bool renderedge;
		int align;
		int selectionx;
		int selectiony;
		bool hideselection;
		void render( int x = -1, int y = -1 );
		int update( );
		void add( std::string str, int itemdata = 0 );
		void set( int index, std::string str, int itemdata = 0 );
		const char *getstr( int index );
		int getitemdata( int index = -1 );
		void remove( int index );
		void clear( );
		void reset(	 );
		int getcount();
		void initwithconfig( const char *configname );
	};

	struct TextBox
	{
		TextBox()
		{
			page = 0;
			backcolor = screen_backcolor;
			forcolor = 0xff000000;
			drawedge = true;
		}
		StrVec contents;
		gcn::Rectangle area;
		int page;
		int forcolor;
		int backcolor;
		bool drawedge;
		void render( int x = -1, int y = -1 );
		int update( );
		void addline( std::string str );
		void initwithconfig( const char *configname );
		void reset();
	};
}

#endif